package com.skt.common_hr.medicalmoney_sac.model
{
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.medicalmoney_sac.model.vo.SupportStandardVO;

	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class SupportStandardProxy extends CommonProxy
	{
		public static const NAME:String = "SupportStandardProxy";

		public static const LOAD_SUPPORT_STANDARD_COMPLETE:String = "loadSupportStandardComplete";
		public static const LOAD_SUPPORT_STANDARD_FAILED:String = "loadSupportStandardFailed";


		public var standardList:ArrayCollection;
		public var standardExport:Object;

		public function isFuneral(code:String):Boolean
		{
			//for(var vo:SupportStandardVO in standardList) {
			for(var i:int=0; i<standardList.length; i++) {
				var vo:SupportStandardVO = standardList.getItemAt(i) as SupportStandardVO;
				if(code == vo.CORSN) {
					if(vo.ZFNR != "") {
						return true;
					}
					return false;
				}
			}
			return false;
		}

		/**
		 * 생성자
		 *
		 * @param
		 * @return void
		 */
		public function SupportStandardProxy(data:Object=null)
		{
			super(NAME, data);
		}


		//
		public function load(pernr:String):void
		{
			var param:Object = new Object();
			param["I_PERNR"] 	= pernr;
			loadData("Z_HR_0109", param, result, fault);
		}



		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 기타계좌 콤보박스 데이터
		 *
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(retCode==0) {
				standardList = parseStandard(event.result.ITAB1);
				standardExport = event.result;

				facade.sendNotification(LOAD_SUPPORT_STANDARD_COMPLETE, this);
			}
			else {
				facade.sendNotification(LOAD_SUPPORT_STANDARD_FAILED, this);
			}
		}
		/**
		 * 서버에서 오류가 발생했을 처리
		 *
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			facade.sendNotification(LOAD_SUPPORT_STANDARD_FAILED, this)
			;
		}


		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 *
		 * @param ArrayCollection
		 * @return 계좌선택  ArrayCollection
		 */
		private function parseStandard(srcArr:ArrayCollection):ArrayCollection
		{
			var retArr:ArrayCollection = new ArrayCollection();
			for each(var rec:Object in srcArr)
			{
				var vo:SupportStandardVO = new SupportStandardVO();
				vo.COGBN = rec["COGBN"];
				vo.CORSN = rec["CORSN"];
				vo.ZTEXT = rec["ZTEXT"];
				vo.BETRG = rec["BETRG"];
				vo.CODAY = rec["CODAY"];
				vo.ZWRTH = (rec["ZWRTH"] == "X") ? "○" : "";
				vo.ZDOCU = rec["ZDOCU"];
				vo.ZFNR =  (rec["ZFNR"] == "X") ? "○" : "";
				// 예외 처리
				// Network O&S의 경우 자녀출생시에 무급 유급 표시를 위해 Comment를 붙인다.
				if(Variables.company=="NOS" && vo.CORSN == "300") {
					vo.comment = vo.CODAY + "(유급:1, 무급:2)";
				}
				retArr.addItem(vo);
			}
			return retArr;
		}
	}
}